package com.zrrd.learn.chapter05;
import java.util.Scanner;
/**
 * 六道题
 *
 * @author wrn
 * @version 1.0
 * @date 2023/6/10 9:01
 */

public class test1 {

    /**
     * 1: 定义四个整数，将它们互相替换例如：i=1;j=2;a=3,b=4,要求输出i=2;j=3;a=4;b=1
     */
    public static void questionOne01() {
        int i=1,j=2,a=3,b=4;
        System.out.printf("i=%d,j=%d,a=%d,b=%d\n",i,j,a,b);
        //        要求: 可以定义新的变量多个
        int x=i;
        int y=j;
        int z=a;
        int f=b;
        i = y;
        j = z;
        a = f;
        b = x;
        System.out.printf("i=%d,j=%d,a=%d,b=%d\n",i,j,a,b);
    }

    public static void questionOne02() {
        int i=1,j=2,a=3,b=4;
        System.out.printf("i=%d,j=%d,a=%d,b=%d\n",i,j,a,b);
        //        只能定义一个新的变量完成
        int t=i;
        i=j;
        j=a;
        a=b;
        b=t;
        System.out.printf("i=%d,j=%d,a=%d,b=%d\n",i,j,a,b);
    }

    public static void questionOne03(){
        int i=1,j=2,a=3,b=4;
        System.out.printf("i=%d,j=%d,a=%d,b=%d\n",i,j,a,b);
        //        不能定义新的变量完成
        j=i+j;
        i=j-i;
        j=j-i;

        a=j+a;
        j=a-j;
        a=a-j;

        b=a+b;
        a=b-a;
        b=b-a;

        i=i+b;
        b=i-b;
        i=i-b;
        System.out.printf("i=%d,j=%d,a=%d,b=%d\n",i,j,a,b);
    }

    /**
     * 2: 定义一个5位整数 值随意  int i=52637;  打印各个位置上的数  个位值 i%10
     */

    public static void questionTwo01(){
        int i=52637;
        int g=i%10;
        int s=i%100/10;
        int b=i%1000/100;
        int q=i%10000/1000;
        int w=i/10000;
        System.out.printf("个位%d\n，十位%d\n，百位%d\n，千位%d\n，万位%d\n",g,s,b,q,w);
    }

    private  final  static  int TWO_MIN_VALUE = 10000;
    private  final  static  int TWO_MAX_VALUE = 99999;

    public static void questionTwo02(int num){
        if (num < TWO_MIN_VALUE || num > TWO_MAX_VALUE) {
            throw new RuntimeException("对不起，请输入五位正整数！！！");
        }

        /**
         * 十进制用来求进制
         */
        int ten = 10;
        for (int i = num, j = 0; i > 0; i /= ten) {
            System.out.printf("%s位是%d\n", getPosition(j), num / (int) Math.pow(10, j++) % 10);
        }
    }

    /**
     * 根据 数字求位
     *
     * @param i
     * @return
     */
    private static String getPosition(int i) {
        switch (i) {
            case 0:
                return "个位";
            case 1:
                return "十位";
            case 2:
                return "百位";
            case 3:
                return "千位";
            case 4:
                return "万位";
            default:
                return "十万位";
        }
    }

    public static void main(String[] args) {

//        questionOne01();
//        questionOne02();
//        questionOne03();
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入一个五位数!!!");
        int n = scanner.nextInt();
        questionTwo02(n);

    }

}
